package com.okaixz.manager.controller;

import com.okaixz.client.model.domain.KbAssistant;
import com.okaixz.common.annotation.Anonymous;
import com.okaixz.common.annotation.Log;
import com.okaixz.common.client.Result;
import com.okaixz.common.core.controller.BaseController;
import com.okaixz.common.core.domain.AjaxResult;
import com.okaixz.common.core.page.TableDataInfo;
import com.okaixz.common.enums.BusinessType;
import com.okaixz.common.utils.poi.ExcelUtil;
import com.okaixz.manager.service.IKbAssistantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * ai应用信息Controller
 *
 * @author ruoyi
 * @date 2025-05-14
 */
@RestController
@Anonymous
@RequestMapping("/manager/kbAssistant")
public class KbAssistantController extends BaseController
{
    @Autowired
    private IKbAssistantService kbAssistantService;

    /**
     * 查询ai应用信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(KbAssistant kbAssistant)
    {
        startPage();
        List<KbAssistant> list = kbAssistantService.selectKbAssistantList(kbAssistant);
        return getDataTable(list);
    }
    /**
     * 查询ai应用信息列表
     */
    @GetMapping("/list/{tabId}")
    public Result<List<KbAssistant>> list(@PathVariable("tabId") Integer tabId)
    {
        List<KbAssistant> list = kbAssistantService.selectKbAssistantListByTabId(tabId);
        return Result.success(list);
    }

    /**
     * 导出ai应用信息列表
     */
    @PreAuthorize("@ss.hasPermi('manager:kbAssistant:export')")
    @Log(title = "ai应用信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KbAssistant kbAssistant)
    {
        List<KbAssistant> list = kbAssistantService.selectKbAssistantList(kbAssistant);
        ExcelUtil<KbAssistant> util = new ExcelUtil<KbAssistant>(KbAssistant.class);
        util.exportExcel(response, list, "ai应用信息数据");
    }

    /**
     * 获取ai应用信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('manager:kbAssistant:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(kbAssistantService.selectKbAssistantById(id));
    }

    /**
     * 新增ai应用信息
     */
    @PreAuthorize("@ss.hasPermi('manager:kbAssistant:add')")
    @Log(title = "ai应用信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KbAssistant kbAssistant)
    {
        return toAjax(kbAssistantService.insertKbAssistant(kbAssistant));
    }

    /**
     * 修改ai应用信息
     */
    @PreAuthorize("@ss.hasPermi('manager:kbAssistant:edit')")
    @Log(title = "ai应用信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KbAssistant kbAssistant)
    {
        return toAjax(kbAssistantService.updateKbAssistant(kbAssistant));
    }

    /**
     * 删除ai应用信息
     */
    @PreAuthorize("@ss.hasPermi('manager:kbAssistant:remove')")
    @Log(title = "ai应用信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(kbAssistantService.deleteKbAssistantByIds(ids));
    }
}
